﻿using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing;
using System.Drawing;
using System.Drawing.Imaging;
using BZOrderPrint.DAL.Entity;
using BZOrderPrint.BLL.Model;
using BZOrderPrint.BLL.Helper;
using static BZOrderPrint.DAL.AppEnum;
using BZOrderPrint.PDF.Model;
using System.Drawing.Printing;
using System.Diagnostics;

namespace BZOrderPrint.PDF
{
    public static class PDFHelper
    {
        public static IntPtr GenerateBarcode(string barcode)
        {
            BarcodeWriter writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.CODE_128;
            writer.Options = new ZXing.Common.EncodingOptions
            {
                Height = 50,
                Width = 100,
                PureBarcode = false,
            };
            Bitmap bitmap = writer.Write(barcode);
            return bitmap.GetHbitmap();
        }

        /// <summary>
        /// 网店面单
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static string CreateShopOrderPDF(BzOrderEntity order)
        {
            string pdfPath = AppDomain.CurrentDomain.BaseDirectory + @"PDFFile\Ship\";
            string logoPath = System.AppDomain.CurrentDomain.BaseDirectory + @"File\logo.jpg";
            string codePath = System.AppDomain.CurrentDomain.BaseDirectory + @"File\code.png";


            if (Directory.Exists(pdfPath) == false)
                Directory.CreateDirectory(pdfPath);


            //iTextSharp.text.Rectangle rectangle = new iTextSharp.text.Rectangle(0, 0,200f, 300f);
            Document doc = new Document(PageSize.A7, 0, 0, 10, -20);
            pdfPath += order.OrderCode + ".pdf";
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdfPath, FileMode.Create));
            doc.Open();
            BaseFont baseFT = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT3 = BaseFont.CreateFont(@"c:\windows\fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(baseFT, 9f);
            iTextSharp.text.Font font1 = new iTextSharp.text.Font(baseFT2, 8f);
            iTextSharp.text.Font font2 = new iTextSharp.text.Font(baseFT3, 7f);
            PdfPTable table = new PdfPTable(2);
            table.TotalWidth = 180f;
            table.LockedWidth = true;

            var logo = iTextSharp.text.Image.GetInstance(logoPath, true);
            logo.Alignment = Element.ALIGN_CENTER;
            PdfPCell cell1 = new PdfPCell(logo);
            cell1.FixedHeight = 46f;
            cell1.Colspan = 2;
            cell1.UseAscender = true;
            cell1.UseDescender = true;
            cell1.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell1.HorizontalAlignment = Element.ALIGN_CENTER; //水平居中
            table.AddCell(cell1);

            Paragraph paragraph = new Paragraph();
            Chunk chunk1 = new Chunk("物流信息", font);
            Chunk chunk2 = new Chunk("门店:" + order.OrderShopName, font1);
            Chunk chunk3 = new Chunk("匹配网点:" + order.OrderShopName, font1);
            paragraph.Add(chunk1);
            paragraph.Add(Chunk.NEWLINE);
            paragraph.Add(chunk2);
            paragraph.Add(Chunk.NEWLINE);
            paragraph.Add(chunk3);
            PdfPCell cell2 = new PdfPCell(paragraph);
            cell2.Colspan = 2;
            table.AddCell(cell2);

            string name = !string.IsNullOrEmpty(order.MemberName) ? order.MemberName : order.Phone;
            Paragraph paragraph2 = new Paragraph();
            Chunk chunk4 = new Chunk("收件人信息", font);
            Chunk chunk5 = new Chunk("姓名:" + name, font1);
            Chunk chunk6 = new Chunk("电话:" + order.Phone, font1);
            paragraph2.Add(chunk4);
            paragraph2.Add(Chunk.NEWLINE);
            paragraph2.Add(chunk5);
            paragraph2.Add(Chunk.NEWLINE);
            paragraph2.Add(chunk6);
            PdfPCell cell3 = new PdfPCell(paragraph2);
            cell3.Colspan = 2;
            table.AddCell(cell3);

            var bmp = GenerateBarcode(order.OrderCode);
            var txm = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromHbitmap(bmp), ImageFormat.Bmp);
            txm.Alignment = Element.ALIGN_CENTER;
            //Chunk chunk8 = new Chunk("订单号", font1);
            //Chunk chunk9 = new Chunk(txm, 0, 0);
            //paragraph3.Add(chunk8);
            //paragraph3.Add(Chunk.NEWLINE);
            //paragraph3.Add(chunk9);
            PdfPCell cell4 = new PdfPCell(txm);
            cell1.FixedHeight = 60f;
            cell4.Colspan = 2;
            cell4.UseAscender = true;
            cell4.VerticalAlignment = Element.ALIGN_CENTER;
            cell4.HorizontalAlignment = Element.ALIGN_CENTER; //水平居中
            table.AddCell(cell4);

            Paragraph paragraph4 = new Paragraph();
            Chunk chunk10 = new Chunk("温馨提示", font);
            Chunk chunk11 = new Chunk("捌爪提醒您请仔细检查货物外观是否完整，如发现异常应第一时间与我们联系处理，您可以扫描下面二维码直接进行售后申诉。", font2);
            paragraph4.Add(chunk10);
            paragraph4.Add(Chunk.NEWLINE);
            paragraph4.Add(chunk11);
            PdfPCell cell5 = new PdfPCell(paragraph4);
            cell5.Colspan = 2;
            table.AddCell(cell5);

            Paragraph paragraph5 = new Paragraph();
            Chunk chunk12 = new Chunk("扫码后请认真填写相关信息，我们会在收到您的申诉后尽快护理", font2);
            paragraph5.Add(chunk12);
            PdfPCell cell6 = new PdfPCell(paragraph5);
            cell5.Colspan = 1;
            table.AddCell(cell6);

            var code = iTextSharp.text.Image.GetInstance(codePath, true);
            code.Alignment = Element.ALIGN_CENTER;
            PdfPCell cell7 = new PdfPCell(code);
            cell7.FixedHeight = 80f;
            cell7.Colspan = 1;
            cell7.UseAscender = true;
            cell7.UseDescender = true;
            cell7.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell7.HorizontalAlignment = Element.ALIGN_CENTER; //水平居中
            table.AddCell(cell7);
            doc.Add(table);
            doc.Close();

            return pdfPath;
        }

        /// <summary>
        /// 团长面单
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static string CreateTeamOrderPDF(BzOrderEntity order)
        {
            string pdfPath = AppDomain.CurrentDomain.BaseDirectory + @"PDFFile\Ship\";
            string logoPath = System.AppDomain.CurrentDomain.BaseDirectory + @"File\logo.jpg";
            string codePath = System.AppDomain.CurrentDomain.BaseDirectory + @"File\code.png";


            if (Directory.Exists(pdfPath) == false)
                Directory.CreateDirectory(pdfPath);

            //iTextSharp.text.Rectangle rectangle = new iTextSharp.text.Rectangle(0, 0, 200f, 300f);
            Document doc = new Document(PageSize.A7, 0, 0, 10, -20);
            pdfPath += order.OrderCode + ".pdf";
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdfPath, FileMode.Create));
            doc.Open();
            BaseFont baseFT = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT3 = BaseFont.CreateFont(@"c:\windows\fonts\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font = new iTextSharp.text.Font(baseFT, 9f);
            iTextSharp.text.Font font1 = new iTextSharp.text.Font(baseFT2, 8f);
            iTextSharp.text.Font font2 = new iTextSharp.text.Font(baseFT3, 7f);
            PdfPTable table = new PdfPTable(2);
            table.TotalWidth = 150f;
            table.LockedWidth = true;

            var logo = iTextSharp.text.Image.GetInstance(logoPath, true);
            logo.Alignment = Element.ALIGN_CENTER;
            PdfPCell cell1 = new PdfPCell(logo);
            cell1.FixedHeight = 46f;
            cell1.Colspan = 2;
            cell1.UseAscender = true;
            cell1.UseDescender = true;
            cell1.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell1.HorizontalAlignment = Element.ALIGN_CENTER; //水平居中
            table.AddCell(cell1);

            Paragraph paragraph = new Paragraph();
            Chunk chunk1 = new Chunk("物流信息", font);
            Chunk chunk2 = new Chunk("门店:" + order.OrderShopName, font1);
            Chunk chunk14 = new Chunk("团长地址:" + order.Address, font1);
            Chunk chunk3 = new Chunk("匹配网点:" + order.OrderShopName, font1);
            paragraph.Add(chunk1);
            paragraph.Add(Chunk.NEWLINE);
            paragraph.Add(chunk2);
            paragraph.Add(Chunk.NEWLINE);
            paragraph.Add(chunk14);
            paragraph.Add(Chunk.NEWLINE);
            paragraph.Add(chunk3);
            PdfPCell cell2 = new PdfPCell(paragraph);
            cell2.Colspan = 2;
            table.AddCell(cell2);

            string name = !string.IsNullOrEmpty(order.MemberName) ? order.MemberName : order.Phone;
            Paragraph paragraph2 = new Paragraph();
            Chunk chunk4 = new Chunk("团长信息", font);
            Chunk chunk5 = new Chunk("姓名:" + name, font1);
            Chunk chunk6 = new Chunk("电话:" + order.Phone, font1);
            paragraph2.Add(chunk4);
            paragraph2.Add(Chunk.NEWLINE);
            paragraph2.Add(chunk5);
            paragraph2.Add(Chunk.NEWLINE);
            paragraph2.Add(chunk6);
            PdfPCell cell3 = new PdfPCell(paragraph2);
            cell3.Colspan = 2;
            table.AddCell(cell3);

            //var bmp = GenerateBarcode(order.OrderCode);
            //var txm = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromHbitmap(bmp), ImageFormat.Bmp);
            //txm.Alignment = Element.ALIGN_CENTER;
            ////Chunk chunk8 = new Chunk("订单号", font1);
            ////Chunk chunk9 = new Chunk(txm, 0, 0);
            ////paragraph3.Add(chunk8);
            ////paragraph3.Add(Chunk.NEWLINE);
            ////paragraph3.Add(chunk9);
            //PdfPCell cell4 = new PdfPCell(txm);
            //cell1.FixedHeight = 60f;
            //cell4.Colspan = 2;
            //cell4.UseAscender = true;
            //cell4.VerticalAlignment = Element.ALIGN_CENTER;
            //cell4.HorizontalAlignment = Element.ALIGN_CENTER; //水平居中
            //table.AddCell(cell4);

            Paragraph paragraph4 = new Paragraph();
            Chunk chunk10 = new Chunk("温馨提示", font);
            Chunk chunk11 = new Chunk("捌爪提醒您请仔细检查货物外观是否完整，如发现异常应第一时间与我们联系处理，您可以扫描下面二维码直接进行售后申诉。", font2);
            paragraph4.Add(chunk10);
            paragraph4.Add(Chunk.NEWLINE);
            paragraph4.Add(chunk11);
            PdfPCell cell5 = new PdfPCell(paragraph4);
            cell5.Colspan = 2;
            table.AddCell(cell5);

            Paragraph paragraph5 = new Paragraph();
            Chunk chunk12 = new Chunk("扫码后请认真填写相关信息，我们会在收到您的申诉后尽快护理", font2);
            paragraph5.Add(chunk12);
            PdfPCell cell6 = new PdfPCell(paragraph5);
            cell5.Colspan = 1;
            table.AddCell(cell6);

            var code = iTextSharp.text.Image.GetInstance(codePath, true);
            code.Alignment = Element.ALIGN_CENTER;
            PdfPCell cell7 = new PdfPCell(code);
            cell7.FixedHeight = 80f;
            cell7.Colspan = 1;
            cell7.UseAscender = true;
            cell7.UseDescender = true;
            cell7.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell7.HorizontalAlignment = Element.ALIGN_CENTER; //水平居中
            table.AddCell(cell7);
            doc.Add(table);
            doc.Close();

            return pdfPath;
        }

        /// <summary>
        /// 捌爪拣货单(网店订单)
        /// </summary>
        /// <returns></returns>
        public static string CreateShopOrderPackagePDF(ShopPackageOrder order)
        {
            string pdfPath = AppDomain.CurrentDomain.BaseDirectory + @"PDFFile\Package\";

            if (Directory.Exists(pdfPath) == false)
                Directory.CreateDirectory(pdfPath);

            Document doc = new Document(PageSize.A4, 0, 0, 10, -50);
            string pdfFullPath = pdfPath + order.YbOrderCode + ".pdf";
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdfFullPath, FileMode.Create));
            doc.Open();
            //BaseFont baseFT = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            //BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT1 = BaseFont.CreateFont(@"c:\windows\fonts\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyh.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font1 = new iTextSharp.text.Font(baseFT1, 15f);
            iTextSharp.text.Font font2 = new iTextSharp.text.Font(baseFT2, 10f);
            iTextSharp.text.Font font3 = new iTextSharp.text.Font(baseFT1, 10f);

            Paragraph Title = new Paragraph("捌爪拣货单", font1);
            Title.Alignment = Element.ALIGN_CENTER;
            doc.Add(Title);
            doc.Add(Chunk.NEWLINE);
            PdfPTable table = new PdfPTable(7);
            Paragraph paragraph1 = new Paragraph();
            Chunk chunk1 = new Chunk("订单号:" + order.YbOrderCode, font3);
            paragraph1.Add(chunk1);
            PdfPCell cell1 = new PdfPCell(paragraph1);
            cell1.Colspan = 4;
            cell1.UseAscender = true;
            cell1.UseDescender = true;
            cell1.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell1.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell1);

            Paragraph paragraph2 = new Paragraph();
            Chunk chunk2 = new Chunk("门店:" + order.ShopName, font3);
            paragraph2.Add(chunk2);
            PdfPCell cell2 = new PdfPCell(paragraph2);
            cell2.Colspan = 3;
            cell2.UseAscender = true;
            cell2.UseDescender = true;
            cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell2.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell2);

            Paragraph paragraph3 = new Paragraph();
            Chunk chunk3 = new Chunk("姓名:" + order.ShopAdmin, font3);
            paragraph3.Add(chunk3);
            PdfPCell cell3 = new PdfPCell(paragraph3);
            cell3.Colspan = 4;
            cell3.UseAscender = true;
            cell3.UseDescender = true;
            cell3.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell3.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell3);

            Paragraph paragraph4 = new Paragraph();
            Chunk chunk4 = new Chunk("电话:" + order.Phone, font3);
            paragraph4.Add(chunk4);
            PdfPCell cell4 = new PdfPCell(paragraph4);
            cell4.Colspan = 3;
            cell4.UseAscender = true;
            cell4.UseDescender = true;
            cell4.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell4.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell4);

            Paragraph paragraph5 = new Paragraph();
            Chunk chunk5 = new Chunk("匹配网点:" + order.ShopName, font3);
            paragraph5.Add(chunk5);
            PdfPCell cell5 = new PdfPCell(paragraph5);
            cell5.Colspan = 7;
            cell5.UseAscender = true;
            cell5.UseDescender = true;
            cell5.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell5.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell5);

            //Paragraph paragraph6 = new Paragraph();
            //Chunk chunk6 = new Chunk("配送方式:" + EnumHelper.GetDescription((ShipMethodType)item.order.ShipMethod), font3);
            //paragraph6.Add(chunk6);
            //PdfPCell cell6 = new PdfPCell(paragraph6);
            //cell6.Colspan = 2;
            //cell6.UseAscender = true;
            //cell6.UseDescender = true;
            //cell6.VerticalAlignment = Element.ALIGN_MIDDLE;
            //cell6.HorizontalAlignment = Element.ALIGN_LEFT;
            //table.AddCell(cell6);

            Paragraph paragraph7 = new Paragraph();
            Chunk chunk7 = new Chunk("商品名", font2);
            paragraph7.Add(chunk7);
            PdfPCell cell7 = new PdfPCell(paragraph7);
            cell7.Colspan = 2;
            cell7.UseAscender = true;
            cell7.UseDescender = true;
            cell7.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell7.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell7);

            Paragraph paragraph8 = new Paragraph();
            Chunk chunk8 = new Chunk("条码", font2);
            paragraph8.Add(chunk8);
            PdfPCell cell8 = new PdfPCell(paragraph8);
            cell8.Colspan = 2;
            cell8.UseAscender = true;
            cell8.UseDescender = true;
            cell8.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell8.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell8);

            Paragraph paragraph9 = new Paragraph();
            Chunk chunk9 = new Chunk("单价", font2);
            paragraph9.Add(chunk9);
            PdfPCell cell9 = new PdfPCell(paragraph9);
            cell9.Colspan = 1;
            cell9.UseAscender = true;
            cell9.UseDescender = true;
            cell9.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell9.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell9);

            Paragraph paragraph10 = new Paragraph();
            Chunk chunk10 = new Chunk("数量", font2);
            paragraph10.Add(chunk10);
            PdfPCell cell10 = new PdfPCell(paragraph10);
            cell10.Colspan = 1;
            cell10.UseAscender = true;
            cell10.UseDescender = true;
            cell10.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell10.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell10);

            Paragraph paragraph11 = new Paragraph();
            Chunk chunk11 = new Chunk("金额", font2);
            paragraph11.Add(chunk11);
            PdfPCell cell11 = new PdfPCell(paragraph11);
            cell11.Colspan = 1;
            cell11.UseAscender = true;
            cell11.UseDescender = true;
            cell11.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell11.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell11);

            foreach (var info in order.orderItems)
            {
                Paragraph paragraph12 = new Paragraph();
                Chunk chunk12 = new Chunk(info.OrderItem, font3);
                paragraph12.Add(chunk12);
                PdfPCell cell12 = new PdfPCell(paragraph12);
                cell12.Colspan = 2;
                cell12.UseAscender = true;
                cell12.UseDescender = true;
                cell12.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell12.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell12);

                Paragraph paragraph13 = new Paragraph();
                Chunk chunk13 = new Chunk(info.OrderItemCode, font3);
                paragraph13.Add(chunk13);
                PdfPCell cell13 = new PdfPCell(paragraph13);
                cell13.Colspan = 2;
                cell13.UseAscender = true;
                cell13.UseDescender = true;
                cell13.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell13.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell13);

                Paragraph paragraph14 = new Paragraph();
                Chunk chunk14 = new Chunk(info.Price.ToString(), font3);
                paragraph14.Add(chunk14);
                PdfPCell cell14 = new PdfPCell(paragraph14);
                cell14.Colspan = 1;
                cell14.UseAscender = true;
                cell14.UseDescender = true;
                cell14.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell14.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell14);

                Paragraph paragraph15 = new Paragraph();
                Chunk chunk15 = new Chunk(info.Quantity.ToString(), font3);
                paragraph15.Add(chunk15);
                PdfPCell cell15 = new PdfPCell(paragraph15);
                cell15.Colspan = 1;
                cell15.UseAscender = true;
                cell15.UseDescender = true;
                cell15.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell15.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell15);

                Paragraph paragraph16 = new Paragraph();
                Chunk chunk16 = new Chunk((info.Price * info.Quantity).ToString(), font3);
                paragraph16.Add(chunk16);
                PdfPCell cell16 = new PdfPCell(paragraph16);
                cell16.Colspan = 1;
                cell16.UseAscender = true;
                cell16.UseDescender = true;
                cell16.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell16.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell16);

                //Paragraph paragraph17 = new Paragraph();
                //Chunk chunk17 = new Chunk(" ", font3);
                //paragraph17.Add(chunk17);
                //PdfPCell cell17 = new PdfPCell(paragraph17);
                //cell17.Colspan = 7;
                //table.AddCell(cell17);
            }

            Paragraph paragraph18 = new Paragraph();
            Chunk chunk18 = new Chunk("总额", font2);
            paragraph18.Add(chunk18);
            PdfPCell cell18 = new PdfPCell(paragraph18);
            cell18.Colspan = 2;
            cell18.UseAscender = true;
            cell18.UseDescender = true;
            cell18.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell18.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell18);

            Paragraph paragraph19 = new Paragraph();
            Chunk chunk19 = new Chunk(order.orderItems.Sum(x => x.Price * x.Quantity).ToString(), font2);
            paragraph19.Add(chunk19);
            PdfPCell cell19 = new PdfPCell(paragraph19);
            cell19.Colspan = 5;
            cell19.UseAscender = true;
            cell19.UseDescender = true;
            cell19.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell19.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell19);
            doc.Add(table);
            doc.Close();

            return pdfFullPath;
        }

        /// <summary>
        /// 捌爪拣货单(社区团购)
        /// </summary>
        /// <returns></returns>
        public static string CreateTeamOrderPackagePDF(TeamPackageOrder order)
        {
            string pdfPath = AppDomain.CurrentDomain.BaseDirectory + @"PDFFile\Package\";

            if (Directory.Exists(pdfPath) == false)
                Directory.CreateDirectory(pdfPath);

            Document doc = new Document(PageSize.A4, 0, 0, 10, -50);
            string pdfFullPath = pdfPath + order.YbOrderCode + ".pdf";
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdfFullPath, FileMode.Create));
            doc.Open();
            //BaseFont baseFT = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            //BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT1 = BaseFont.CreateFont(@"c:\windows\fonts\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyh.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font1 = new iTextSharp.text.Font(baseFT1, 15f);
            iTextSharp.text.Font font2 = new iTextSharp.text.Font(baseFT2, 10f);
            iTextSharp.text.Font font3 = new iTextSharp.text.Font(baseFT1, 10f);

            Paragraph Title = new Paragraph("捌爪拣货单", font1);
            Title.Alignment = Element.ALIGN_CENTER;
            doc.Add(Title);
            doc.Add(Chunk.NEWLINE);
            PdfPTable table = new PdfPTable(7);
            table.SetWidths(new float[] { 200, 200, 200, 150, 150, 80, 80 });
            Paragraph paragraph1 = new Paragraph();
            Chunk chunk1 = new Chunk("团长:" + order.AdminName, font3);
            paragraph1.Add(chunk1);
            PdfPCell cell1 = new PdfPCell(paragraph1);
            cell1.Colspan = 4;
            cell1.UseAscender = true;
            cell1.UseDescender = true;
            cell1.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell1.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell1);

            Paragraph paragraph2 = new Paragraph();
            Chunk chunk2 = new Chunk("门店:" + order.ShopName, font3);
            paragraph2.Add(chunk2);
            PdfPCell cell2 = new PdfPCell(paragraph2);
            cell2.Colspan = 3;
            cell2.UseAscender = true;
            cell2.UseDescender = true;
            cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell2.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell2);

            Paragraph paragraph3 = new Paragraph();
            Chunk chunk3 = new Chunk("姓名:" + order.AdminName, font3);
            paragraph3.Add(chunk3);
            PdfPCell cell3 = new PdfPCell(paragraph3);
            cell3.Colspan = 4;
            cell3.UseAscender = true;
            cell3.UseDescender = true;
            cell3.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell3.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell3);

            Paragraph paragraph4 = new Paragraph();
            Chunk chunk4 = new Chunk("电话:" + order.Phone, font3);
            paragraph4.Add(chunk4);
            PdfPCell cell4 = new PdfPCell(paragraph4);
            cell4.Colspan = 3;
            cell4.UseAscender = true;
            cell4.UseDescender = true;
            cell4.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell4.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell4);

            Paragraph paragraph20 = new Paragraph();
            Chunk chunk20 = new Chunk("团长地址:" + order.AdminAddress, font3);
            paragraph20.Add(chunk20);
            PdfPCell cell20 = new PdfPCell(paragraph20);
            cell20.Colspan = 7;
            cell20.UseAscender = true;
            cell20.UseDescender = true;
            cell20.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell20.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell20);

            Paragraph paragraph5 = new Paragraph();
            Chunk chunk5 = new Chunk("匹配网点:" + order.ShopName, font3);
            paragraph5.Add(chunk5);
            PdfPCell cell5 = new PdfPCell(paragraph5);
            cell5.Colspan = 7;
            cell5.UseAscender = true;
            cell5.UseDescender = true;
            cell5.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell5.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell5);

            //Paragraph paragraph6 = new Paragraph();
            //Chunk chunk6 = new Chunk("配送方式:" + EnumHelper.GetDescription((ShipMethodType)item.order.ShipMethod), font3);
            //paragraph6.Add(chunk6);
            //PdfPCell cell6 = new PdfPCell(paragraph6);
            //cell6.Colspan = 2;
            //cell6.UseAscender = true;
            //cell6.UseDescender = true;
            //cell6.VerticalAlignment = Element.ALIGN_MIDDLE;
            //cell6.HorizontalAlignment = Element.ALIGN_LEFT;
            //table.AddCell(cell6);

            Paragraph paragraph7 = new Paragraph();
            Chunk chunk7 = new Chunk("商品名", font2);
            paragraph7.Add(chunk7);
            PdfPCell cell7 = new PdfPCell(paragraph7);
            cell7.Colspan = 4;
            cell7.UseAscender = true;
            cell7.UseDescender = true;
            cell7.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell7.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell7);

            Paragraph paragraph8 = new Paragraph();
            Chunk chunk8 = new Chunk("条码", font2);
            paragraph8.Add(chunk8);
            PdfPCell cell8 = new PdfPCell(paragraph8);
            cell8.Colspan = 2;
            cell8.UseAscender = true;
            cell8.UseDescender = true;
            cell8.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell8.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell8);

            //Paragraph paragraph9 = new Paragraph();
            //Chunk chunk9 = new Chunk("单价", font2);
            //paragraph9.Add(chunk9);
            //PdfPCell cell9 = new PdfPCell(paragraph9);
            //cell9.Colspan = 1;
            //cell9.UseAscender = true;
            //cell9.UseDescender = true;
            //cell9.VerticalAlignment = Element.ALIGN_MIDDLE;
            //cell9.HorizontalAlignment = Element.ALIGN_CENTER;
            //table.AddCell(cell9);

            Paragraph paragraph10 = new Paragraph();
            Chunk chunk10 = new Chunk("数量", font2);
            paragraph10.Add(chunk10);
            PdfPCell cell10 = new PdfPCell(paragraph10);
            cell10.Colspan = 1;
            cell10.UseAscender = true;
            cell10.UseDescender = true;
            cell10.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell10.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell10);

            //Paragraph paragraph11 = new Paragraph();
            //Chunk chunk11 = new Chunk("金额", font2);
            //paragraph11.Add(chunk11);
            //PdfPCell cell11 = new PdfPCell(paragraph11);
            //cell11.Colspan = 1;
            //cell11.UseAscender = true;
            //cell11.UseDescender = true;
            //cell11.VerticalAlignment = Element.ALIGN_MIDDLE;
            //cell11.HorizontalAlignment = Element.ALIGN_CENTER;
            //table.AddCell(cell11);

            foreach (var info in order.orderItems)
            {
                Paragraph paragraph12 = new Paragraph();
                Chunk chunk12 = new Chunk(info.OrderItem, font3);
                paragraph12.Add(chunk12);
                PdfPCell cell12 = new PdfPCell(paragraph12);
                cell12.Colspan = 4;
                cell12.UseAscender = true;
                cell12.UseDescender = true;
                cell12.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell12.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell12);

                Paragraph paragraph13 = new Paragraph();
                Chunk chunk13 = new Chunk(info.OrderItemCode, font3);
                paragraph13.Add(chunk13);
                PdfPCell cell13 = new PdfPCell(paragraph13);
                cell13.Colspan = 2;
                cell13.UseAscender = true;
                cell13.UseDescender = true;
                cell13.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell13.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell13);

                //Paragraph paragraph14 = new Paragraph();
                //Chunk chunk14 = new Chunk(info.Price.ToString(), font3);
                //paragraph14.Add(chunk14);
                //PdfPCell cell14 = new PdfPCell(paragraph14);
                //cell14.Colspan = 1;
                //cell14.UseAscender = true;
                //cell14.UseDescender = true;
                //cell14.VerticalAlignment = Element.ALIGN_MIDDLE;
                //cell14.HorizontalAlignment = Element.ALIGN_CENTER;
                //table.AddCell(cell14);

                Paragraph paragraph15 = new Paragraph();
                Chunk chunk15 = new Chunk(info.Quantity.ToString(), font3);
                paragraph15.Add(chunk15);
                PdfPCell cell15 = new PdfPCell(paragraph15);
                cell15.Colspan = 1;
                cell15.UseAscender = true;
                cell15.UseDescender = true;
                cell15.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell15.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell15);

                //Paragraph paragraph16 = new Paragraph();
                //Chunk chunk16 = new Chunk((info.Price * info.Quantity).ToString(), font3);
                //paragraph16.Add(chunk16);
                //PdfPCell cell16 = new PdfPCell(paragraph16);
                //cell16.Colspan = 1;
                //cell16.UseAscender = true;
                //cell16.UseDescender = true;
                //cell16.VerticalAlignment = Element.ALIGN_MIDDLE;
                //cell16.HorizontalAlignment = Element.ALIGN_CENTER;
                //table.AddCell(cell16);

                //Paragraph paragraph17 = new Paragraph();
                //Chunk chunk17 = new Chunk(" ", font3);
                //paragraph17.Add(chunk17);
                //PdfPCell cell17 = new PdfPCell(paragraph17);
                //cell17.Colspan = 7;
                //table.AddCell(cell17);
            }

            Paragraph paragraph18 = new Paragraph();
            Chunk chunk18 = new Chunk("总额", font2);
            paragraph18.Add(chunk18);
            PdfPCell cell18 = new PdfPCell(paragraph18);
            cell18.Colspan = 2;
            cell18.UseAscender = true;
            cell18.UseDescender = true;
            cell18.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell18.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell18);

            Paragraph paragraph19 = new Paragraph();
            Chunk chunk19 = new Chunk(order.orderItems.Sum(x => x.Quantity).ToString(), font2);
            paragraph19.Add(chunk19);
            PdfPCell cell19 = new PdfPCell(paragraph19);
            cell19.Colspan = 5;
            cell19.UseAscender = true;
            cell19.UseDescender = true;
            cell19.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell19.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell19);
            doc.Add(table);
            doc.Close();
            return pdfFullPath;
        }

        /// <summary>
        /// 网店取货单
        /// </summary>
        public static string CreateShopOrderPickUpPDF(List<ShopPickUpOrder> pickUpOrders)
        {
            string pdfPath = AppDomain.CurrentDomain.BaseDirectory + @"PDFFile\PickUp\";

            if (Directory.Exists(pdfPath) == false)
                Directory.CreateDirectory(pdfPath);

            Document doc = new Document(PageSize.A4, 0, 0, 10, -50);
            string pdfFullPath = pdfPath + pickUpOrders.FirstOrDefault().WhloeOrderCorde + ".pdf";
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdfFullPath, FileMode.Create));
            doc.Open();
            //BaseFont baseFT = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            //BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT1 = BaseFont.CreateFont(@"c:\windows\fonts\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyh.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font1 = new iTextSharp.text.Font(baseFT1, 15f);
            iTextSharp.text.Font font2 = new iTextSharp.text.Font(baseFT2, 10f);
            iTextSharp.text.Font font3 = new iTextSharp.text.Font(baseFT1, 10f);

            Paragraph Title = new Paragraph("捌爪取货对货单（普通网单）", font1);
            Title.Alignment = Element.ALIGN_CENTER;
            doc.Add(Title);
            doc.Add(Chunk.NEWLINE);
            PdfPTable table = new PdfPTable(7);
            table.SetWidths(new float[] { 200, 200, 200, 150, 150, 100, 150 });
            Paragraph paragraph1 = new Paragraph();
            Chunk chunk1 = new Chunk("门店:" + pickUpOrders.FirstOrDefault().ShopName, font3);
            paragraph1.Add(chunk1);
            PdfPCell cell1 = new PdfPCell(paragraph1);
            cell1.Colspan = 7;
            cell1.UseAscender = true;
            cell1.UseDescender = true;
            cell1.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell1.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell1);

            Paragraph paragraph2 = new Paragraph();
            Chunk chunk2 = new Chunk("匹配网点:" + pickUpOrders.FirstOrDefault().ShopName, font3);
            paragraph2.Add(chunk2);
            PdfPCell cell2 = new PdfPCell(paragraph2);
            cell2.Colspan = 7;
            cell2.UseAscender = true;
            cell2.UseDescender = true;
            cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell2.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell2);

            Paragraph paragraph3 = new Paragraph();
            Chunk chunk3 = new Chunk("订单号", font2);
            paragraph3.Add(chunk3);
            PdfPCell cell3 = new PdfPCell(paragraph3);
            cell3.Colspan = 1;
            cell3.UseAscender = true;
            cell3.UseDescender = true;
            cell3.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell3.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell3);

            Paragraph paragraph4 = new Paragraph();
            Chunk chunk4 = new Chunk("商品名", font2);
            paragraph4.Add(chunk4);
            PdfPCell cell4 = new PdfPCell(paragraph4);
            cell4.Colspan = 1;
            cell4.UseAscender = true;
            cell4.UseDescender = true;
            cell4.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell4.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell4);

            Paragraph paragraph5 = new Paragraph();
            Chunk chunk5 = new Chunk("条码", font2);
            paragraph5.Add(chunk5);
            PdfPCell cell5 = new PdfPCell(paragraph5);
            cell5.Colspan = 1;
            cell5.UseAscender = true;
            cell5.UseDescender = true;
            cell5.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell5.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell5);

            Paragraph paragraph6 = new Paragraph();
            Chunk chunk6 = new Chunk("姓名", font2);
            paragraph6.Add(chunk6);
            PdfPCell cell6 = new PdfPCell(paragraph6);
            cell6.Colspan = 1;
            cell6.UseAscender = true;
            cell6.UseDescender = true;
            cell6.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell6.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell6);

            Paragraph paragraph7 = new Paragraph();
            Chunk chunk7 = new Chunk("电话", font2);
            paragraph7.Add(chunk7);
            PdfPCell cell7 = new PdfPCell(paragraph7);
            cell7.Colspan = 1;
            cell7.UseAscender = true;
            cell7.UseDescender = true;
            cell7.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell7.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell7);

            Paragraph paragraph8 = new Paragraph();
            Chunk chunk8 = new Chunk("数量", font2);
            paragraph8.Add(chunk8);
            PdfPCell cell8 = new PdfPCell(paragraph8);
            cell8.Colspan = 1;
            cell8.UseAscender = true;
            cell8.UseDescender = true;
            cell8.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell8.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell8);

            Paragraph paragraph9 = new Paragraph();
            Chunk chunk9 = new Chunk("取货登记", font2);
            paragraph9.Add(chunk9);
            PdfPCell cell9 = new PdfPCell(paragraph9);
            cell9.Colspan = 1;
            cell9.UseAscender = true;
            cell9.UseDescender = true;
            cell9.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell9.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell9);

            foreach (var item in pickUpOrders)
            {
                Paragraph paragraph10 = new Paragraph();
                Chunk chunk10 = new Chunk(item.order.OrderCode, font3);
                paragraph10.Add(chunk10);
                PdfPCell cell10 = new PdfPCell(paragraph10);
                cell10.Rowspan = item.orderItems.Count;
                cell10.Colspan = 1;
                cell10.UseAscender = true;
                cell10.UseDescender = true;
                cell10.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell10.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell10);

                foreach (var info in item.orderItems)
                {
                    Paragraph paragraph11 = new Paragraph();
                    Chunk chunk11 = new Chunk(info.OrderItem, font3);
                    paragraph11.Add(chunk11);
                    PdfPCell cell11 = new PdfPCell(paragraph11);
                    cell11.Colspan = 1;
                    cell11.UseAscender = true;
                    cell11.UseDescender = true;
                    cell11.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell11.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell11);

                    Paragraph paragraph12 = new Paragraph();
                    Chunk chunk12 = new Chunk(info.OrderItemCode, font3);
                    paragraph12.Add(chunk12);
                    PdfPCell cell12 = new PdfPCell(paragraph12);
                    cell12.Colspan = 1;
                    cell12.UseAscender = true;
                    cell12.UseDescender = true;
                    cell12.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell12.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell12);

                    Paragraph paragraph13 = new Paragraph();
                    string name = !string.IsNullOrEmpty(item.order.MemberName) ? item.order.MemberName : item.order.Phone;
                    Chunk chunk13 = new Chunk(name, font3);
                    paragraph13.Add(chunk13);
                    PdfPCell cell13 = new PdfPCell(paragraph13);
                    cell13.Colspan = 1;
                    cell13.UseAscender = true;
                    cell13.UseDescender = true;
                    cell13.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell13.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell13);

                    Paragraph paragraph14 = new Paragraph();
                    Chunk chunk14 = new Chunk(item.order.Phone, font3);
                    paragraph14.Add(chunk14);
                    PdfPCell cell14 = new PdfPCell(paragraph14);
                    cell14.Colspan = 1;
                    cell14.UseAscender = true;
                    cell14.UseDescender = true;
                    cell14.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell14.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell14);

                    Paragraph paragraph15 = new Paragraph();
                    Chunk chunk15 = new Chunk(info.Quantity.ToString(), font3);
                    paragraph15.Add(chunk15);
                    PdfPCell cell15 = new PdfPCell(paragraph15);
                    cell15.Colspan = 1;
                    cell15.UseAscender = true;
                    cell15.UseDescender = true;
                    cell15.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell15.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell15);

                    Paragraph paragraph16 = new Paragraph();
                    Chunk chunk16 = new Chunk(" ", font3);
                    paragraph16.Add(chunk16);
                    PdfPCell cell16 = new PdfPCell(paragraph16);
                    cell16.Colspan = 1;
                    cell16.UseAscender = true;
                    cell16.UseDescender = true;
                    cell16.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell16.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell16);
                }
            }
            Paragraph paragraph17 = new Paragraph();
            Chunk chunk17 = new Chunk("总额", font2);
            paragraph17.Add(chunk17);
            PdfPCell cell17 = new PdfPCell(paragraph17);
            cell17.Colspan = 2;
            cell17.UseAscender = true;
            cell17.UseDescender = true;
            cell17.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell17.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell17);

            Paragraph paragraph18 = new Paragraph();
            Chunk chunk18 = new Chunk(pickUpOrders.Sum(x => x.order.OrderPrice).ToString(), font2);
            paragraph18.Add(chunk18);
            PdfPCell cell18 = new PdfPCell(paragraph18);
            cell18.Colspan = 5;
            cell18.UseAscender = true;
            cell18.UseDescender = true;
            cell18.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell18.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell18);

            doc.Add(table);
            doc.Close();
            return pdfFullPath;
        }

        /// <summary>
        /// 团长取货单
        /// </summary>
        public static string CreateTeamOrderPickUpPDF(TeamPickUpOrder teamPickUpOrder)
        {
            string pdfPath = AppDomain.CurrentDomain.BaseDirectory + @"PDFFile\PickUp\";

            if (Directory.Exists(pdfPath) == false)
                Directory.CreateDirectory(pdfPath);

            Document doc = new Document(PageSize.A4, 0, 0, 10, -50);
            string pdfFullPath = pdfPath + teamPickUpOrder.WhloeOrderCorde + ".pdf";
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdfFullPath, FileMode.Create));
            doc.Open();
            //BaseFont baseFT = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            //BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyhbd.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT1 = BaseFont.CreateFont(@"c:\windows\fonts\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            BaseFont baseFT2 = BaseFont.CreateFont(@"c:\windows\fonts\msyh.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            iTextSharp.text.Font font1 = new iTextSharp.text.Font(baseFT1, 15f);
            iTextSharp.text.Font font2 = new iTextSharp.text.Font(baseFT2, 10f);
            iTextSharp.text.Font font3 = new iTextSharp.text.Font(baseFT1, 10f);

            Paragraph Title = new Paragraph("捌爪取货对货单（社区团购）", font1);
            Title.Alignment = Element.ALIGN_CENTER;
            doc.Add(Title);
            doc.Add(Chunk.NEWLINE);
            PdfPTable table = new PdfPTable(8);
            table.SetWidths(new float[] { 200, 200, 200, 150, 150, 150, 100, 100 });
            Paragraph paragraph1 = new Paragraph();
            Chunk chunk1 = new Chunk("团长:" + teamPickUpOrder.AdminName, font3);
            paragraph1.Add(chunk1);
            PdfPCell cell1 = new PdfPCell(paragraph1);
            cell1.Colspan = 4;
            cell1.UseAscender = true;
            cell1.UseDescender = true;
            cell1.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell1.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell1);

            Paragraph paragraph2 = new Paragraph();
            Chunk chunk2 = new Chunk("门店:" + teamPickUpOrder.ShopName, font3);
            paragraph2.Add(chunk2);
            PdfPCell cell2 = new PdfPCell(paragraph2);
            cell2.Colspan = 4;
            cell2.UseAscender = true;
            cell2.UseDescender = true;
            cell2.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell2.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell2);

            Paragraph paragraph3 = new Paragraph();
            Chunk chunk3 = new Chunk("姓名:" + teamPickUpOrder.AdminName, font3);
            paragraph3.Add(chunk3);
            PdfPCell cell3 = new PdfPCell(paragraph3);
            cell3.Colspan = 4;
            cell3.UseAscender = true;
            cell3.UseDescender = true;
            cell3.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell3.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell3);

            Paragraph paragraph4 = new Paragraph();
            Chunk chunk4 = new Chunk("电话:" + teamPickUpOrder.Phone, font3);
            paragraph4.Add(chunk4);
            PdfPCell cell4 = new PdfPCell(paragraph4);
            cell4.Colspan = 4;
            cell4.UseAscender = true;
            cell4.UseDescender = true;
            cell4.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell4.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell4);

            Paragraph paragraph5 = new Paragraph();
            Chunk chunk5 = new Chunk("团长地址:" + teamPickUpOrder.Address, font3);
            paragraph5.Add(chunk5);
            PdfPCell cell5 = new PdfPCell(paragraph5);
            cell5.Colspan = 8;
            cell5.UseAscender = true;
            cell5.UseDescender = true;
            cell5.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell5.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell5);

            Paragraph paragraph6 = new Paragraph();
            Chunk chunk6 = new Chunk("匹配网点:" + teamPickUpOrder.ShopName, font3);
            paragraph6.Add(chunk6);
            PdfPCell cell6 = new PdfPCell(paragraph6);
            cell6.Colspan = 8;
            cell6.UseAscender = true;
            cell6.UseDescender = true;
            cell6.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell6.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell6);

            Paragraph paragraph7 = new Paragraph();
            Chunk chunk7 = new Chunk("订单号", font2);
            paragraph7.Add(chunk7);
            PdfPCell cell7 = new PdfPCell(paragraph7);
            cell7.Colspan = 1;
            cell7.UseAscender = true;
            cell7.UseDescender = true;
            cell7.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell7.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell7);

            Paragraph paragraph8 = new Paragraph();
            Chunk chunk8 = new Chunk("商品名", font2);
            paragraph8.Add(chunk8);
            PdfPCell cell8 = new PdfPCell(paragraph8);
            cell8.Colspan = 1;
            cell8.UseAscender = true;
            cell8.UseDescender = true;
            cell8.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell8.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell8);

            Paragraph paragraph9 = new Paragraph();
            Chunk chunk9 = new Chunk("条码", font2);
            paragraph9.Add(chunk9);
            PdfPCell cell9 = new PdfPCell(paragraph9);
            cell9.Colspan = 1;
            cell9.UseAscender = true;
            cell9.UseDescender = true;
            cell9.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell9.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell9);

            Paragraph paragraph10 = new Paragraph();
            Chunk chunk10 = new Chunk("姓名", font2);
            paragraph10.Add(chunk10);
            PdfPCell cell10 = new PdfPCell(paragraph10);
            cell10.Colspan = 1;
            cell10.UseAscender = true;
            cell10.UseDescender = true;
            cell10.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell10.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell10);

            Paragraph paragraph11 = new Paragraph();
            Chunk chunk11 = new Chunk("电话", font2);
            paragraph11.Add(chunk11);
            PdfPCell cell11 = new PdfPCell(paragraph11);
            cell11.Colspan = 1;
            cell11.UseAscender = true;
            cell11.UseDescender = true;
            cell11.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell11.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell11);

            Paragraph paragraph12 = new Paragraph();
            Chunk chunk12 = new Chunk("数量", font2);
            paragraph12.Add(chunk12);
            PdfPCell cell12 = new PdfPCell(paragraph12);
            cell12.Colspan = 1;
            cell12.UseAscender = true;
            cell12.UseDescender = true;
            cell12.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell12.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell12);

            Paragraph paragraph13 = new Paragraph();
            Chunk chunk13 = new Chunk("取货登记", font2);
            paragraph13.Add(chunk13);
            PdfPCell cell13 = new PdfPCell(paragraph13);
            cell13.Colspan = 1;
            cell13.UseAscender = true;
            cell13.UseDescender = true;
            cell13.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell13.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell13);

            Paragraph paragraph14 = new Paragraph();
            Chunk chunk14 = new Chunk("备注", font2);
            paragraph14.Add(chunk14);
            PdfPCell cell14 = new PdfPCell(paragraph14);
            cell14.Colspan = 1;
            cell14.UseAscender = true;
            cell14.UseDescender = true;
            cell14.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell14.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell14);

            List<string> orderCodes = teamPickUpOrder.itemEntities.Select(x => x.TeamItemCode).Distinct().ToList();

            foreach (var item in orderCodes)
            {
                var itemList = teamPickUpOrder.itemEntities.Where(x => x.TeamItemCode == item).ToList();
                Paragraph paragraph15 = new Paragraph();
                Chunk chunk15 = new Chunk(item, font3);
                paragraph15.Add(chunk15);
                PdfPCell cell15 = new PdfPCell(paragraph15);
                cell15.Rowspan = itemList.Count;
                cell15.Colspan = 1;
                cell15.UseAscender = true;
                cell15.UseDescender = true;
                cell15.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell15.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(cell15);

                foreach (var info in itemList)
                {
                    Paragraph paragraph16 = new Paragraph();
                    Chunk chunk16 = new Chunk(info.ItemName, font3);
                    paragraph16.Add(chunk16);
                    PdfPCell cell16 = new PdfPCell(paragraph16);
                    cell16.Colspan = 1;
                    cell16.UseAscender = true;
                    cell16.UseDescender = true;
                    cell16.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell16.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell16);

                    Paragraph paragraph17 = new Paragraph();
                    Chunk chunk17 = new Chunk(info.BzItemCodo, font3);
                    paragraph17.Add(chunk17);
                    PdfPCell cell17 = new PdfPCell(paragraph17);
                    cell17.Colspan = 1;
                    cell17.UseAscender = true;
                    cell17.UseDescender = true;
                    cell17.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell17.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell17);

                    string name = !string.IsNullOrEmpty(info.MemberName) ? info.MemberName : info.Phone;
                    Paragraph paragraph18 = new Paragraph();
                    Chunk chunk18 = new Chunk(name, font3);
                    paragraph18.Add(chunk18);
                    PdfPCell cell18 = new PdfPCell(paragraph18);
                    cell18.Colspan = 1;
                    cell18.UseAscender = true;
                    cell18.UseDescender = true;
                    cell18.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell18.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell18);

                    Paragraph paragraph19 = new Paragraph();
                    Chunk chunk19 = new Chunk(info.Phone, font3);
                    paragraph19.Add(chunk19);
                    PdfPCell cell19 = new PdfPCell(paragraph19);
                    cell19.Colspan = 1;
                    cell19.UseAscender = true;
                    cell19.UseDescender = true;
                    cell19.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell19.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell19);

                    Paragraph paragraph20 = new Paragraph();
                    Chunk chunk20 = new Chunk(info.Quantity.ToString(), font3);
                    paragraph20.Add(chunk20);
                    PdfPCell cell20 = new PdfPCell(paragraph20);
                    cell20.Colspan = 1;
                    cell20.UseAscender = true;
                    cell20.UseDescender = true;
                    cell20.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell20.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell20);

                    Paragraph paragraph21 = new Paragraph();
                    Chunk chunk21 = new Chunk(" ", font3);
                    paragraph21.Add(chunk21);
                    PdfPCell cell21 = new PdfPCell(paragraph21);
                    cell21.Colspan = 1;
                    cell21.UseAscender = true;
                    cell21.UseDescender = true;
                    cell21.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell21.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell21);

                    Paragraph paragraph22 = new Paragraph();
                    Chunk chunk22 = new Chunk(" ", font3);
                    paragraph22.Add(chunk22);
                    PdfPCell cell22 = new PdfPCell(paragraph22);
                    cell22.Colspan = 1;
                    cell22.UseAscender = true;
                    cell22.UseDescender = true;
                    cell22.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell22.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.AddCell(cell22);
                }
            }

            Paragraph paragraph23 = new Paragraph();
            Chunk chunk23 = new Chunk("总额", font2);
            paragraph23.Add(chunk23);
            PdfPCell cell23 = new PdfPCell(paragraph23);
            cell23.Colspan = 2;
            cell23.UseAscender = true;
            cell23.UseDescender = true;
            cell23.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell23.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell23);

            Paragraph paragraph24 = new Paragraph();
            Chunk chunk24 = new Chunk(" ", font2);
            paragraph24.Add(chunk24);
            PdfPCell cell24 = new PdfPCell(paragraph24);
            cell24.Colspan = 5;
            cell24.UseAscender = true;
            cell24.UseDescender = true;
            cell24.VerticalAlignment = Element.ALIGN_MIDDLE;
            cell24.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell24);

            doc.Add(table);
            doc.Close();
            return pdfFullPath;
        }

        public static void PrintPDF(string toPath)
        {
            PrintDocument print = new PrintDocument();
            var printerName = print.PrinterSettings.PrinterName;//记录默认打印机名
            try
            {
                Process processInstance = new Process();
                ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    UseShellExecute = true,
                    Verb = "Print",
                    CreateNoWindow = true,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    Arguments = @"/p /h \" + toPath + "\" \"" + printerName + " \"",//pd.PrinterSettings.PrinterName;
                    FileName = toPath
                };
                processInstance.StartInfo = startInfo;
                processInstance.Start();
                processInstance.WaitForExit(6000);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}